package com.xique.park.service.command.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xique.common.core.exception.CustomException;
import com.xique.common.core.utils.command.CommandResultUtil;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.park.api.IParkCommandApi;
import com.xique.park.bean.domain.ParkOn;
import com.xique.park.constant.CommandConstant;
import com.xique.park.constant.ParkApiName;
import com.xique.park.service.command.service.IParkOnCommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 在场命令
 *
 * @author: xique
 */
@Service
public class ParkOnCommandServiceImpl extends CommandCommServiceImpl implements IParkOnCommandService {

    @Autowired
    private IParkCommandApi parkCommandApi;

    @Override
    public AjaxResult batchMarkCarIn(Long parkId, List<ParkOn> list) {
        try {
            JSONObject obj = getBaseObj(parkId, null, ParkApiName.COMMAND_MARK_IN, ParkApiName.VER_2_0);
            JSONObject dataObj = new JSONObject();
            dataObj.put(CommandConstant.LIST, list);
            obj.put(CommandConstant.DATA, dataObj);
            @SuppressWarnings("unchecked")
            Map<String, Object> params = JSONObject.toJavaObject(obj, Map.class);
            AjaxResult result = parkCommandApi.batchMarkCarIn(params);
            return CommandResultUtil.handleCommandResult(result, "");
        } catch (Exception e) {
            throw new CustomException("批量进场接口请求失败！");
        }
    }
}
